﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Profari_Heldur_Utan_Um_Prof
{
    public partial class EditTaskIntro : Form
    {
        private static SqlConnection con = new SqlConnection("Data Source=HlynurX-PC\\SQLEXPRESS;Initial Catalog=lokaverkefni;Integrated Security=True ");
        private static DataTable dt = new DataTable();
        private static SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM IntroBFTask", con);
        private static DataSet ds = new DataSet();
        SqlDataReader r = null;

        int globalProjectID;
        int globalSessionID;

        //data between forms
        public bool editWPUrl;
        public bool introBFSess;
        public bool introBFTask;

        public EditTaskIntro(int projectID, int sessionID)
        {
            InitializeComponent();
            globalProjectID = projectID;
            globalSessionID = sessionID;
            //FillTextBox();
            this.StartPosition = FormStartPosition.CenterScreen;
        }
        /*
        public void FillTextBox()
        {
            try
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("Select intro from IntroBFTask", con);
                r = cmd.ExecuteReader();

                while (r.Read())
                {
                    string thisrow = "";
                    for (int i = 0; i < r.FieldCount; i++)
                        thisrow += r.GetValue(i).ToString();

                    richTextBox1.Text += thisrow;
                }

            }
            catch (SqlException ex)
            {
                Console.WriteLine("Error: {0}", ex.ToString());

            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }
        }
        */
        private void Cancel_Click(object sender, EventArgs e)
        {
            DialogResult cancelProject = MessageBox.Show("Are you sure you want to stop making new project?", "Quit", MessageBoxButtons.YesNo);
            if (cancelProject == DialogResult.Yes)
            {
                TesterInterface testerInterface = new TesterInterface();
                testerInterface.Show();
                this.Close();
                /*
                System.Threading.Thread testerInterface = new System.Threading.Thread(new System.Threading.ThreadStart(OpenTesterInterface));
                testerInterface.Start();
                this.Close();*/
            }
        }

        private void Next_Click(object sender, EventArgs e)
        {
            ListOfSessions listOfSessions = new ListOfSessions(globalProjectID);
            listOfSessions.Show();
            this.Hide();
        }

        private void Back_Click(object sender, EventArgs e)
        {
            if (introBFSess == true)
            {
                EditIntroductionText editIntroductionText = new EditIntroductionText(globalProjectID, globalSessionID);
                editIntroductionText.editWPUrl = editWPUrl;
                editIntroductionText.introBFSess = introBFSess;
                editIntroductionText.Show();
                this.Close();
            }
            else if (editWPUrl == true)
            {
                EditWebPage editWebPage = new EditWebPage(globalProjectID, globalSessionID);
                editWebPage.editWPUrl = editWPUrl;
                editWebPage.introBFSess = introBFSess;
                editWebPage.Show();
                this.Close();
            }
            else
            {
                EditSessions editSession = new EditSessions(globalSessionID, globalSessionID);
                editSession.Show();
                this.Close();
            }
        }
    }
}
